//*****************************************************************
// Project2.cpp
//
//  Created on: Jan 21, 2012
//      Author: Christopher Wood
//              Robert Livosi
//
//  $Id: Project2.cpp 23 2012-01-28 02:51:05Z caw4567@gmail.com $
//*****************************************************************

// Module includes
#include "Project2.h"
#include "IOThreadGroup.h"
#include "PIDTransformThread.h"
#include "PIDControlThread.h"

/**
 * The main entry point for the controller program.
 */
int main(int argc, char *argv[])
{
	int adReturn;
	float val;

	// Get permission to the hardware
	int privity_err = ThreadCtl(_NTO_TCTL_IO, NULL);
	if (privity_err == -1)
	{
		cerr << "Can't get root permissions" << endl;
		exit(-1);
	}

	// Create and then start all threads
	IOThreadGroup* ioGroup = new IOThreadGroup();
	TransformThread* pidTransform = new PIDTransformThread(ioGroup);
	ControlThread* pidControl = new PIDControlThread(pidTransform, ioGroup);
	ioGroup->runInputThread();
	ioGroup->runOutputThread();
	pidTransform->run();
	pidControl->run();

	// Wait until the control thread is complete.
	while (!pidControl->isComplete())
	{
	}

	return EXIT_SUCCESS;
}
